// FrontEnd Plus GUI for JAD
// DeCompiled : HibernateJavaTypeMapper.class

package middlegen.plugins.hibernate;

import middlegen.ColumnDecorator;
import middlegen.javax.JavaColumn;
import middlegen.javax.Sql2Java;
import middlegen.plugins.hibernate.interfaces.JavaTypeMapper;

public class HibernateJavaTypeMapper
    implements JavaTypeMapper
{

    public HibernateJavaTypeMapper()
    {
    }

    public String getPreferredJavaType(JavaColumn column)
    {
        int sqlType = column.getSqlType();
        int size = column.getSize();
        int decimalDigits = column.getDecimalDigits();
        boolean nullable = column.isNullable();
        String result = null;
        if((sqlType == 3 || sqlType == 2) && decimalDigits == 0)
        {
            if(size < 10)
                result = "int";
            else
            if(size < 19)
                result = "long";
            else
                result = "java.math.BigDecimal";
        } else
        if(sqlType == -2 || sqlType == -3 || sqlType == -4)
        {
            result = "binary";
        } else
        {
            result = Sql2Java.getPreferredJavaType(sqlType, size, decimalDigits);
            if(result == null)
                result = "java.lang.Object";
        }
        if((nullable || column.isPk()) && ("int".equals(result) || "short".equals(result) || "long".equals(result) || "byte".equals(result) || "float".equals(result) || "boolean".equals(result) || "double".equals(result)))
            result = Sql2Java.getClassForPrimitive(result);
        return result;
    }
}
